package com.example.parkinglotmanagementsystem;

import java.util.ArrayList;

/**
 * 车辆管理器类，用于管理车辆的添加、删除
 */
public class VehicleManager{
    ArrayList<Vehicle> vehicles;
    ArrayList<Vehicle> vehicles_search;

    public int Max_Count;

    public VehicleManager() {
        Max_Count = 0;
    }

    public void addVehicle(Vehicle vehicle){
        vehicles.add(vehicle);
        Max_Count++;
    }

    public void deleteVehicle(Vehicle vehicle){
        vehicles.remove(vehicle);
        Max_Count--;
    }

    public ArrayList<Vehicle> searchById(int id){
        for(int i = 0 ; i < vehicles.size() ; i ++){
            if(vehicles.get(i).getId() == id)
                vehicles_search.add(vehicles.get(i));
        }
        return vehicles_search;
    }

    public ArrayList<Vehicle> searchByCompany(String company){
        for(int i = 0 ; i < vehicles.size() ; i ++){
            if(vehicles.get(i).getCompany() == company)
                vehicles_search.add(vehicles.get(i));
        }
        return vehicles_search;
    }

    public ArrayList<Vehicle> searchByType(String type){
        for(int i = 0 ; i < vehicles.size() ; i ++){
            if(vehicles.get(i).getType() == type)
                vehicles_search.add(vehicles.get(i));
        }
        return vehicles_search;
    }

    public void changeVehicle(Vehicle vehicle1,Vehicle vehicle2){
        int pos = -1;
        for(int i = 0 ; i < vehicles.size() ; i ++){
            if(vehicles.get(i) == vehicle1)
                pos = i;
        }
        vehicles.add(pos, vehicle2);
        vehicles.remove(vehicle1);
    }
}
